home *** CD-ROM | disk | FTP | other *** search
/ Digital Information Mana…ntial Guide to Multimedia / Digital Information Management - An Essential Guide to Multimedia.iso / Portable / PortableOpenOfficeCode / PortableOpenOffice.nsi < prev    next >
Text File  |  2006-05-16  |  10KB  |  343 lines

  1. ;Copyright (C) 2004-2005 John T. Haller
  2. ;Additional Ideas from tracon and mai9
  3.  
  4. ;Website: http://portableapps.com/portableopenoffice
  5.  
  6. ;This software is OSI Certified Open Source Software.
  7. ;OSI Certified is a certification mark of the Open Source Initiative.
  8.  
  9. ;This program is free software; you can redistribute it and/or
  10. ;modify it under the terms of the GNU General Public License
  11. ;as published by the Free Software Foundation; either version 2
  12. ;of the License, or (at your option) any later version.
  13.  
  14. ;This program is distributed in the hope that it will be useful,
  15. ;but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;GNU General Public License for more details.
  18.  
  19. ;You should have received a copy of the GNU General Public License
  20. ;along with this program; if not, write to the Free Software
  21. ;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  22.  
  23. !define NAME "PortableOpenOffice"
  24. !define FRIENDLYNAME "Portable OpenOffice.org"
  25. !define APP "OpenOffice"
  26. !define VER "1.1.3.0"
  27. !define WEBSITE "portableapps.com/portableopenoffice"
  28. !define DEFAULTEXE "soffice.exe"
  29. !define DEFAULTAPPDIR "openoffice\program"
  30. !define DEFAULTSETTINGSDIR "settings"
  31. !define DEFAULTPARAMETERS ""
  32.  
  33. !include LogicLib.nsh
  34.  
  35. ;=== Program Details
  36. Name "${NAME}"
  37. OutFile "${NAME}.exe"
  38. Caption "${FRIENDLYNAME} - the complete office suite that's completely portable"
  39. VIProductVersion "${VER}.0"
  40. VIAddVersionKey FileDescription "${FRIENDLYNAME}"
  41. VIAddVersionKey LegalCopyright "GPL"
  42. VIAddVersionKey Comments "Allows ${APP} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
  43. VIAddVersionKey CompanyName "by John T. Haller et al"
  44. VIAddVersionKey OriginalFilename "${NAME}.exe"
  45. VIAddVersionKey FileVersion "${VER}"
  46.  
  47. ;=== Runtime Switches
  48. CRCCheck On
  49. WindowIcon Off
  50. SilentInstall Silent
  51. AutoCloseWindow True
  52.  
  53. ;=== Program Icon
  54. Icon "${APP}.ico"
  55.  
  56. Var PROGRAMDIRECTORY
  57. Var SETTINGSDIRECTORY
  58. Var SETTINGSDIRECTORYWITHOUTSPACES
  59. Var SETTINGSDIRECTORYBOOTSTRAP
  60. Var ADDITIONALPARAMETERS
  61. Var EXECSTRING
  62. Var WAITFORPROGRAM
  63. Var PROGRAMEXECUTABLE
  64. Var INIPATH
  65. Var DISABLESPLASHSCREEN
  66.  
  67. !define StrRep "!insertmacro StrRep"
  68.  
  69. !macro StrRep ResultVar String SubString RepString
  70.   Push "${String}"
  71.   Push "${SubString}"
  72.   Push "${RepString}"
  73.   Call StrRep
  74.   Pop "${ResultVar}"
  75. !macroend
  76. Function StrRep
  77. /*After this point:
  78.   ------------------------------------------
  79.   $R0 = RepString (input)
  80.   $R1 = SubString (input)
  81.   $R2 = String (input)
  82.   $R3 = RepStrLen (temp)
  83.   $R4 = SubStrLen (temp)
  84.   $R5 = StrLen (temp)
  85.   $R6 = StartCharPos (temp)
  86.   $R7 = TempStrL (temp)
  87.   $R8 = TempStrR (temp)*/
  88.  
  89.   ;Get input from user
  90.   Exch $R0
  91.   Exch
  92.   Exch $R1
  93.   Exch
  94.   Exch 2
  95.   Exch $R2
  96.   Push $R3
  97.   Push $R4
  98.   Push $R5
  99.   Push $R6
  100.   Push $R7
  101.   Push $R8
  102.  
  103.   ;Return "String" if "SubString" is ""
  104.   ${IfThen} $R1 == "" ${|} Goto Done ${|}
  105.  
  106.   ;Get "RepString", "String" and "SubString" length
  107.   StrLen $R3 $R0
  108.   StrLen $R4 $R1
  109.   StrLen $R5 $R2
  110.   ;Start "StartCharPos" counter
  111.   StrCpy $R6 0
  112.  
  113.   ;Loop until "SubString" is found or "String" reaches its end
  114.   ${Do}
  115.     ;Remove everything before and after the searched part ("TempStrL")
  116.     StrCpy $R7 $R2 $R4 $R6
  117.  
  118.     ;Compare "TempStrL" with "SubString"
  119.     ${If} $R7 == $R1
  120.       ;Split "String" to replace the string wanted
  121.       StrCpy $R7 $R2 $R6 ;TempStrL
  122.  
  123.       ;Calc: "StartCharPos" + "SubStrLen" = EndCharPos
  124.       IntOp $R8 $R6 + $R4
  125.  
  126.       StrCpy $R8 $R2 "" $R8 ;TempStrR
  127.  
  128.       ;Insert the new string between the two separated parts of "String"
  129.       StrCpy $R2 $R7$R0$R8
  130.       ;Now calculate the new "StrLen" and "StartCharPos"
  131.       StrLen $R5 $R2
  132.       IntOp $R6 $R6 + $R3
  133.       ${Continue}
  134.     ${EndIf}
  135.  
  136.     ;If not "SubString", this could be "String" end
  137.     ${IfThen} $R6 >= $R5 ${|} ${ExitDo} ${|}
  138.     ;If not, continue the loop
  139.     IntOp $R6 $R6 + 1
  140.   ${Loop}
  141.  
  142.   Done:
  143.  
  144.   ;Return output to user
  145.   StrCpy $R0 $R2
  146.  
  147. /*After this point:
  148.   ------------------------------------------
  149.   $R0 = ResultVar (output)*/
  150.  
  151.   Pop $R8
  152.   Pop $R7
  153.   Pop $R6
  154.   Pop $R5
  155.   Pop $R4
  156.   Pop $R3
  157.   Pop $R2
  158.   Pop $R1
  159.   Exch $R0
  160. FunctionEnd
  161.  
  162.  
  163. Section "Main"
  164.     ;=== Find the INI file, if there is one
  165.         IfFileExists "$EXEDIR\${NAME}.ini" "" CheckSubINI
  166.             StrCpy "$INIPATH" "$EXEDIR\"
  167.             Goto ReadINI
  168.  
  169.     CheckSubINI:
  170.         IfFileExists "$EXEDIR\${NAME}\${NAME}.ini" "" CheckSubSubINI
  171.             StrCpy "$INIPATH" "$EXEDIR\${NAME}\"
  172.             Goto ReadINI
  173.  
  174.     CheckSubSubINI:
  175.         IfFileExists "$EXEDIR\PortableApps\${NAME}\${NAME}.ini" "" CheckPortableAppsINI
  176.             StrCpy "$INIPATH" "$EXEDIR\PortableApps\${NAME}\"
  177.             Goto ReadINI
  178.  
  179.     CheckPortableAppsINI:
  180.         IfFileExists "$EXEDIR\Data\${NAME}\${NAME}.ini" ""  NoINI
  181.             StrCpy "$INIPATH" "$EXEDIR\Data\${NAME}\"
  182.             Goto ReadINI
  183.  
  184.     ReadINI:
  185.         ;=== Read the parameters from the INI file
  186.         ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APP}Directory"
  187.         StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\$0"
  188.         ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
  189.         StrCpy "$SETTINGSDIRECTORY" "$0"
  190.  
  191.         ;=== Check that the above required parameters are present
  192.         IfErrors NoINI
  193.  
  194.         ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters"
  195.         StrCpy "$ADDITIONALPARAMETERS" $0
  196.         ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "WaitFor${APP}"
  197.         StrCpy "$WAITFORPROGRAM" $0
  198.         ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APP}Executable"
  199.         StrCpy "$PROGRAMEXECUTABLE" $0
  200.         ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen"
  201.         StrCpy "$DISABLESPLASHSCREEN" $0
  202.  
  203.         ;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
  204.         ClearErrors
  205.  
  206.         ;=== Correct PROGRAMEXECUTABLE if blank
  207.         StrCmp $PROGRAMEXECUTABLE "" "" EndINI
  208.             StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
  209.             Goto EndINI
  210.  
  211.     NoINI:
  212.         ;=== No INI file, so we'll use the defaults
  213.         StrCpy "$ADDITIONALPARAMETERS" ""
  214.         StrCpy "$WAITFORPROGRAM" "false"
  215.         StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
  216.         StrCpy "$DISABLESPLASHSCREEN" "false"
  217.  
  218.         IfFileExists "$EXEDIR\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" CheckPortableProgramDIR
  219.             StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\${DEFAULTAPPDIR}"
  220.             StrCpy "$SETTINGSDIRECTORY" "${DEFAULTSETTINGSDIR}"
  221.             GoTo EndINI
  222.  
  223.         CheckPortableProgramDIR:
  224.             IfFileExists "$EXEDIR\${NAME}\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" CheckPortableAppsDIR
  225.             StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\${NAME}\${DEFAULTAPPDIR}"
  226.             StrCpy "$SETTINGSDIRECTORY" "${NAME}\${DEFAULTSETTINGSDIR}"
  227.             GoTo EndINI
  228.  
  229.         CheckPortableAppsDIR:
  230.             IfFileExists "$EXEDIR\PortableApps\${NAME}\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" CheckPortableAppsSplitDIR
  231.             StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\PortableApps\${NAME}\${DEFAULTAPPDIR}"
  232.             StrCpy "$SETTINGSDIRECTORY" "PortableApps\${NAME}\${DEFAULTSETTINGSDIR}"
  233.             GoTo EndINI
  234.  
  235.         CheckPortableAppsSplitDIR:
  236.             IfFileExists "$EXEDIR\Apps\${NAME}\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
  237.             StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\Apps\${NAME}\${DEFAULTAPPDIR}"
  238.             StrCpy "$SETTINGSDIRECTORY" "Data\${NAME}\${DEFAULTSETTINGSDIR}"
  239.  
  240.     EndINI:
  241.         IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE
  242.  
  243.     NoProgramEXE:
  244.         ;=== Program executable not where expected
  245.         MessageBox MB_OK|MB_ICONEXCLAMATION `$PROGRAMEXECUTABLE was not found.  Please check your configuration`
  246.         Abort
  247.         
  248.     FoundProgramEXE:
  249.         FindProcDLL::FindProc "soffice.bin"
  250.         Pop $R0
  251.         StrCmp $R0 "1" "" ShowSplashScreen
  252.         IfFileExists "$SETTINGSDIRECTORY\.lock" SkipSplashScreen
  253.     
  254.     ShowSplashScreen:
  255.         StrCmp $DISABLESPLASHSCREEN "true" SkipSplashScreen
  256.  
  257.         InitPluginsDir
  258.         File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"
  259.         newadvsplash::show /NOUNLOAD 3000 200 200 -1 /L $PLUGINSDIR\splash.jpg
  260.     
  261.     SkipSplashScreen:
  262.         ;=== Get any passed parameters
  263.         Call GetParameters
  264.         Pop $0
  265.         StrCmp "'$0'" "''" "" LaunchProgramParameters
  266.  
  267.         ;=== No parameters
  268.         StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"`
  269.         Goto AdditionalParameters
  270.  
  271.     LaunchProgramParameters:
  272.         StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" $0`
  273.  
  274.     AdditionalParameters:
  275.         StrCpy $EXECSTRING `$EXECSTRING${DEFAULTPARAMETERS}`
  276.     
  277.         StrCmp $ADDITIONALPARAMETERS "" SetSettingsPath
  278.  
  279.         ;=== Additional Parameters
  280.         StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`
  281.  
  282.     SetSettingsPath:
  283.         ;=== Set the settngs directory if we have a path
  284.         IfFileExists `$PROGRAMDIRECTORY\bootstrap.ini` ""  NoBootStrap
  285.             ${StrRep} $SETTINGSDIRECTORYWITHOUTSPACES "$EXEDIR\$SETTINGSDIRECTORY" " " "%20"
  286.             ${StrRep} $SETTINGSDIRECTORYBOOTSTRAP $SETTINGSDIRECTORYWITHOUTSPACES "\" "/"
  287.             ;MessageBox MB_OK|MB_ICONINFORMATION `file:///$SETTINGSDIRECTORYBOOTSTRAP`
  288.             WriteINIStr `$PROGRAMDIRECTORY\bootstrap.ini` "Bootstrap" "UserInstallation" "file:///$SETTINGSDIRECTORYBOOTSTRAP"
  289.             Goto LaunchNow
  290.  
  291.     NoBootStrap:
  292.         MessageBox MB_OK|MB_ICONEXCLAMATION `$PROGRAMDIRECTORY\bootstrap.ini was not found.  Please check your configuration`
  293.         Abort
  294.  
  295.     LaunchNow:
  296.         StrCmp $WAITFORPROGRAM "true" LaunchAndWait LaunchAndClose
  297.  
  298.     LaunchAndWait:
  299.         ExecWait $EXECSTRING
  300.         GoTo TheEnd
  301.  
  302.     LaunchAndClose:
  303.         Exec $EXECSTRING
  304.  
  305.     TheEnd:
  306.         Sleep 4000 ;=== Ensure the splash is closed
  307. SectionEnd
  308.  
  309. Function "GetParameters"
  310.   Push $R0
  311.   Push $R1
  312.   Push $R2
  313.   StrCpy $R0 $CMDLINE 1
  314.   StrCpy $R1 '"'
  315.   StrCpy $R2 1
  316.   StrCmp $R0 '"' loop
  317.     StrCpy $R1 ' ' ; we're scanning for a space instead of a quote
  318.   loop:
  319.     StrCpy $R0 $CMDLINE 1 $R2
  320.     StrCmp $R0 $R1 loop2
  321.     StrCmp $R0 "\" "" "nofile"
  322.       IntOp $2 $R2 + 1
  323.     nofile:
  324.     ;MessageBox MB_OK "r0: $R0"
  325.     StrCmp $R0 "" loop2
  326.     IntOp $R2 $R2 + 1
  327.     Goto loop
  328.   loop2:
  329.     IntOp $R0 $R2 - $2
  330.     IntOp $R0 $R0 - 4
  331.     ;MessageBox MB_OK "$R2 - $2 = $R0"
  332.     StrCpy $R7 $CMDLINE $R0 $2 ; we save the filename
  333.     ;MessageBox MB_OK "$2"
  334.   loop2b:
  335.     IntOp $R2 $R2 + 1
  336.     StrCpy $R0 $CMDLINE 1 $R2
  337.     ;MessageBox MB_OK "rr0: $R0"
  338.     StrCmp $R0 " " loop2b
  339.   StrCpy $R0 $CMDLINE "" $R2
  340.   Pop $R2
  341.   Pop $R1
  342.   Exch $R0
  343. FunctionEnd